home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / seahaven.scm < prev    next >
Encoding:
Text File  |  2009-04-14  |  10.1 KB  |  338 lines

  1. ; AisleRiot - seahaven.scm
  2. ; Copyright (C) 2001 Rosanna Yuen <zana@webwynk.net>
  3. ;
  4. ; This game is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2, or (at your option)
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (def-save-var free-reserves 0)
  20.  
  21. (define foundation '(0 1 6 7))
  22. (define freecells '(2 3 4 5))
  23. (define tableau '(8 9 10 11 12 13 14 15 16 17))
  24.  
  25. (define (new-game)
  26.   (initialize-playing-area)
  27.   (set-ace-low)
  28.   (make-standard-deck)
  29.   (shuffle-deck)
  30.  
  31.   (add-normal-slot DECK)
  32.   (add-normal-slot '())
  33.  
  34.   (add-blank-slot)
  35.  
  36.   (add-normal-slot '())
  37.   (add-normal-slot '())
  38.   (add-normal-slot '())
  39.   (add-normal-slot '())
  40.  
  41.   (add-blank-slot)
  42.  
  43.   (add-normal-slot '())
  44.   (add-normal-slot '())
  45.  
  46.   (add-carriage-return-slot)
  47.  
  48.   (add-extended-slot '() down)
  49.   (add-extended-slot '() down)
  50.   (add-extended-slot '() down)
  51.   (add-extended-slot '() down)
  52.   (add-extended-slot '() down)
  53.   (add-extended-slot '() down)
  54.   (add-extended-slot '() down)
  55.   (add-extended-slot '() down)
  56.   (add-extended-slot '() down)
  57.   (add-extended-slot '() down)
  58.  
  59.   (deal-cards-face-up 0 '(8 9 10 11 12 13 14 15 16 17 8 9 10 11 12 13
  60.                 14 15 16 17 8 9 10 11 12 13 14 15 16 17 8
  61.                 9 10 11 12 13 14 15 16 17 8 9 10 11 12 13 
  62.                 14 15 16 17 3 4))
  63.  
  64.   (set! free-reserves 2)
  65.  
  66.   (list 10 4))
  67.  
  68. (define (sequence-matches-slot? card-list slot)
  69.   (and (not (empty-slot? slot))
  70.        (= (get-suit (car card-list))
  71.       (get-suit (get-top-card slot)))
  72.        (= (get-value (car card-list))
  73.       (+ 1 (get-value (get-top-card slot))))))
  74.  
  75. (define (button-pressed slot-id card-list)
  76.   (and (not (empty-slot? slot-id))
  77.        (or (= (length card-list) 1)
  78.        (and (> slot-id 7)
  79.         (< (length card-list) (+ 2 free-reserves))
  80.         (check-same-suit-list card-list)
  81.         (check-straight-descending-list card-list))
  82.        (and (> slot-id 7) ; Move an entire sequence to the foundation
  83.         (check-same-suit-list card-list)
  84.         (check-straight-descending-list card-list)
  85.         (or (sequence-matches-slot? card-list 0)
  86.             (sequence-matches-slot? card-list 1)
  87.             (sequence-matches-slot? card-list 6)
  88.             (sequence-matches-slot? card-list 7))))))
  89.  
  90. (define (droppable? start-slot card-list end-slot)
  91.   (cond ((= start-slot end-slot)
  92.      #f)
  93.     ((> end-slot 7) ; The tableau
  94.      (and (or (and (empty-slot? end-slot)
  95.                (= (get-value (car (reverse card-list)))
  96.               king))
  97.           (and (not (empty-slot? end-slot))
  98.                (= (get-suit (get-top-card end-slot))
  99.               (get-suit (car card-list)))
  100.                (= (get-value (get-top-card end-slot))
  101.               (+ 1 (get-value (car (reverse card-list)))))))
  102.               (< (length card-list) (+ 2 free-reserves))
  103.           (or (> start-slot 7)
  104.           (and (> start-slot 1)
  105.                (< start-slot 6)))))
  106.     ((and (> end-slot 1) ; The free reserves
  107.           (< end-slot 6))
  108.      (and (= (length card-list) 1)
  109.           (empty-slot? end-slot)))
  110.     (else ; otherwise it is the foundations
  111.      (cond ((empty-slot? end-slot) 
  112.         (= (get-value (car card-list)) ace))
  113.            (else
  114.         (and (= (get-suit (get-top-card end-slot))
  115.             (get-suit (car card-list)))
  116.              (= (+ 1 (get-value (get-top-card end-slot)))
  117.             (get-value (car card-list)))))))))
  118.  
  119. (define (button-released start-slot card-list end-slot)
  120.   (cond ((= start-slot end-slot)
  121.      #f)
  122.     ((> end-slot 7)
  123.      (and (or (and (empty-slot? end-slot)
  124.                (= (get-value (car (reverse card-list)))
  125.               king)
  126.                (move-n-cards! start-slot end-slot card-list))
  127.           (and (not (empty-slot? end-slot))
  128.                (= (get-suit (get-top-card end-slot))
  129.               (get-suit (car card-list)))
  130.                (= (get-value (get-top-card end-slot))
  131.               (+ 1 (get-value (car (reverse card-list)))))
  132.                (move-n-cards! start-slot end-slot card-list)))
  133.           (or (> start-slot 7)
  134.           (and (> start-slot 1)
  135.                (< start-slot 6)
  136.                (set! free-reserves (+ 1 free-reserves)))
  137.           (add-to-score! -1))))
  138.     ((and (= (length card-list) 1)
  139.           (empty-slot? end-slot)
  140.           (> end-slot 1)
  141.           (< end-slot 6))
  142.      (and (move-n-cards! start-slot end-slot card-list)
  143.           (or (and (> start-slot 1)
  144.                (< start-slot 6))
  145.           (set! free-reserves (- free-reserves 1)))))
  146.     ((and (= (length card-list) 1)
  147.           (or (< end-slot 2)
  148.           (and (> end-slot 5)
  149.                (< end-slot 8))))
  150.      (and (or (and (empty-slot? end-slot)
  151.                (= (get-value (car card-list)) ace))
  152.           (and (not (empty-slot? end-slot))
  153.                (= (get-suit (get-top-card end-slot))
  154.               (get-suit (car card-list)))
  155.                (= (+ 1 (get-value (get-top-card end-slot)))
  156.               (get-value (car card-list)))))
  157.           (move-n-cards! start-slot end-slot card-list)
  158.           (or (and (> start-slot 7)
  159.                (add-to-score! 1))
  160.           (and (> start-slot 1)
  161.                (< start-slot 6)
  162.                (set! free-reserves (+ free-reserves 1))
  163.                (add-to-score! 1))
  164.           #t)))
  165.     ((and (or (< end-slot 2) ; Move an entire sequence to the foundation
  166.           (= end-slot 6)
  167.           (= end-slot 7))
  168.           (check-same-suit-list card-list)
  169.           (check-straight-descending-list card-list)
  170.           (sequence-matches-slot? card-list end-slot)) 
  171.      (and (move-n-cards! start-slot end-slot (reverse card-list))
  172.           (add-to-score! (length card-list))
  173.           #t))
  174.     (#t #f)))
  175.  
  176. (define (button-clicked slot-id)
  177.   #f)
  178.  
  179. (define (move-to-empty-foundation slot f-slot)
  180.   (cond ((= f-slot 2)
  181.      (move-to-empty-foundation slot 6))
  182.     ((= f-slot 8)
  183.      #f)
  184.     ((empty-slot? f-slot)
  185.      (deal-cards slot (list f-slot)))
  186.     (#t (move-to-empty-foundation slot (+ 1 f-slot)))))
  187.  
  188. (define (move-to-foundation slot f-slot)
  189.   (cond ((= f-slot 2)
  190.      (move-to-foundation slot 6))
  191.     ((= f-slot 8)
  192.      #f)
  193.     ((and (not (empty-slot? f-slot))
  194.           (= (get-suit (get-top-card slot))
  195.          (get-suit (get-top-card f-slot))))
  196.      (and (= (get-value (get-top-card slot))
  197.          (+ 1 (get-value (get-top-card f-slot))))
  198.           (deal-cards slot (list f-slot))))
  199.     (#t (move-to-foundation slot (+ 1 f-slot)))))
  200.  
  201. (define (autoplay-foundations)
  202.   (define (autoplay-foundations-tail)
  203.     (if (or-map button-double-clicked (append freecells tableau))
  204.         (delayed-call autoplay-foundations-tail)
  205.         #t))
  206.   (if (or-map button-double-clicked (append freecells tableau))
  207.       (autoplay-foundations-tail)
  208.       #f))
  209.  
  210. (define (button-double-clicked slot-id)
  211.   (or (and (member slot-id foundation)
  212.        (autoplay-foundations))
  213.       (and (not (empty-slot? slot-id))
  214.        (> slot-id 1)
  215.        (or (< slot-id 6)
  216.            (> slot-id 7))
  217.        (or (and (= (get-value (get-top-card slot-id))
  218.                ace)
  219.             (move-to-empty-foundation slot-id 0))
  220.            (move-to-foundation slot-id 0))
  221.        (add-to-score! 1)
  222.        (or (> slot-id 7)
  223.            (set! free-reserves (+ 1 free-reserves))))))
  224.  
  225. (define (game-continuable)
  226.   (and (not (game-won))
  227.        (get-hint)))
  228.  
  229. (define (game-won)
  230.   (and (= (length (get-cards 0)) 13)
  231.        (= (length (get-cards 1)) 13)
  232.        (= (length (get-cards 6)) 13)
  233.        (= (length (get-cards 7)) 13)))
  234.  
  235. (define (check-to-foundations? slot f-slot)
  236.   (cond ((= slot 18)
  237.      #f)
  238.     ((= slot 6)
  239.      (check-to-foundations? 8 0))
  240.     ((= f-slot 2)
  241.      (check-to-foundations? slot 6))
  242.     ((or (empty-slot? slot)
  243.          (= f-slot 8))
  244.      (check-to-foundations? (+ 1 slot) 0))
  245.     ((= (get-value (get-top-card slot)) ace)
  246.      (list 2 (get-name (get-top-card slot)) (_"an empty foundation")))
  247.     ((and (not (empty-slot? f-slot))
  248.           (= (get-suit (get-top-card slot))
  249.          (get-suit (get-top-card f-slot)))
  250.           (= (get-value (get-top-card slot))
  251.          (+ 1 (get-value (get-top-card f-slot)))))
  252.      (list 1 (get-name (get-top-card slot)) (get-name (get-top-card f-slot))))
  253.     (#t (check-to-foundations? slot (+ 1 f-slot)))))
  254.  
  255. (define (check-for-king card-list iter slot)
  256.   (cond ((= (length card-list) 0)
  257.      #f)
  258.     ((and (= (length card-list) 1)
  259.           (> slot 7))
  260.      #f)
  261.     ((= (get-value (car card-list)) king)
  262.      (get-name (car card-list)))
  263.     ((= iter 0)
  264.      #f)
  265.     ((and (> (length card-list)1)
  266.           (= (get-suit (car card-list))
  267.          (get-suit (cadr card-list)))
  268.           (= (+ 1 (get-value (car card-list)))
  269.          (get-value (cadr card-list))))
  270.      (check-for-king (cdr card-list) (- iter 1) slot))
  271.     (#t #f)))
  272.  
  273. (define (check-for-spec-card card-list iter value)
  274.   (cond ((= (length card-list) 0)
  275.      #f)
  276.     ((= (get-value (car card-list)) value)
  277.      #t)
  278.     ((= iter 0)
  279.      #f)
  280.     ((and (> (length card-list) 1)
  281.           (= (get-suit (car card-list))
  282.          (get-suit (cadr card-list)))
  283.           (= (+ 1 (get-value (car card-list)))
  284.          (get-value (cadr card-list))))
  285.      (check-for-spec-card (cdr card-list) (- iter 1) value))
  286.     (#t #f)))
  287.  
  288. (define (check-to-tableau? slot t-slot)
  289.   (cond ((= slot 18)
  290.      #f)
  291.     ((= slot 6)
  292.      (check-to-tableau? 8 9))
  293.     ((or (empty-slot? slot)
  294.          (= t-slot 18))
  295.      (check-to-tableau? (+ 1 slot) 8))
  296.     ((and (not (= slot t-slot))
  297.           (empty-slot? t-slot)
  298.           (check-for-king (get-cards slot) free-reserves slot))
  299.      (list 2 
  300.            (check-for-king (get-cards slot) free-reserves slot) 
  301.            (_"an empty tableau")))
  302.     ((and (not (= slot t-slot))
  303.           (not (empty-slot? t-slot))
  304.           (= (get-suit (get-top-card slot))
  305.          (get-suit (get-top-card t-slot)))
  306.           (check-for-spec-card (get-cards slot) 
  307.                    free-reserves 
  308.                    (- (get-value (get-top-card t-slot)) 1)))
  309.      (list 1 
  310.            (get-name (make-card (- (get-value (get-top-card t-slot)) 1)
  311.                     (get-suit (get-top-card t-slot))))
  312.            (get-name (get-top-card t-slot))))
  313.     (#t (check-to-tableau? slot (+ 1 t-slot)))))
  314.  
  315. (define (check-for-empty-reserve)
  316.   (and (> free-reserves 0)
  317.        (list 0 (_"Move something on to an empty reserve"))))
  318.  
  319. (define (get-hint)
  320.   (or (check-to-foundations? 2 0)
  321.       (check-to-tableau? 2 8)
  322.       (check-for-empty-reserve)))
  323.  
  324. (define (get-options) 
  325.   #f)
  326.  
  327. (define (apply-options options) 
  328.   #f)
  329.  
  330. (define (timeout) 
  331.   #f)
  332.  
  333. (set-features droppable-feature)
  334.  
  335. (set-lambda new-game button-pressed button-released button-clicked
  336. button-double-clicked game-continuable game-won get-hint get-options
  337. apply-options timeout droppable?)
  338.